### Replication code for "Misdemeanor Disenfranchisement?"
### October 2018
### See the readme file for more details on what goes where in this replication package
### Contact Ariel White with questions: arwhi@mit.edu

print "running!"
from nameparser import HumanName

candfile = "Harrisco_defendantnames_indsubset.txt"
newcandfile = "Harrisco_defendantnames_indsubset_parsed.txt"

myname = str("Ms. Ariel R. White")

f = open(candfile, "r")
o = open(newcandfile, "wb")
o.write("DefFullName" + "|" + "DefLastName" + "|" + "DefFirstName" + "|" + "DefMiddleName") # + "|" + "DefSuffix")
o.write('\n')
counter = 1
for line in f:
	counter +=1
#	print line
	splits = line.split('" "')
	dadname = splits[0].strip('"')
#	print dadname
	if counter ==12263:
	#	break
		print line.strip('\n')[1:len(line.strip('\n'))-1]
	name1 = HumanName(dadname.strip('\n').strip('"').replace("'", ""))
	if counter == 3:
		print line
		print name1
#	print name1
	o.write(name1.full_name.strip('"').replace("'", "").encode('utf-8'))
	o.write("|")
	o.write(name1.last.encode('utf-8'))
	o.write("|")
	o.write(name1.first.encode('utf-8'))
	o.write("|")
	o.write(name1.middle.encode('utf-8'))
	o.write('\n')

f.close()

print HumanName(myname).last
print HumanName("Paul Holvey").last
